angular.module('orderModule',[])
    .controller('orderCtr',['$scope','httpFactory','$filter',function($scope,httpFactory,$filter){
        $scope.goBack=function(){
            window.history.back();
        };
        $scope.newDatas=[];
        var orderData=LsyStorage.getItem('orderDatas');
        httpFactory.getData('src/datas/proData.json')
            .then(function(data){
                $scope.newDatas = $filter('orderFilter')(data, orderData);
                $scope.filterDatas=$scope.newDatas;
            });
        $scope.index=0;
        $scope.navArr=['全部','待付款','待收货','待发货'];
        $scope.tab=function(key,text){
            $scope.index=key;
            $scope.filterDatas=[];
            if(text=='待付款'){
                angular.forEach($scope.newDatas,function(item){
                    if(item.status==0){
                        $scope.filterDatas.push(item);
                    }
                });
            }else if(text=='待收货' || text=='待发货'){
                angular.forEach($scope.newDatas,function(item){
                    if(item.status==1){
                        $scope.filterDatas.push(item);
                    }
                });
            }else if(text=='全部'){
                $scope.filterDatas= $scope.newDatas;
            }
        };
        /*点击删除*/
        $scope.remove=function(index){
            var newOrderData=LsyStorage.getItem('orderDatas');
            angular.forEach(newOrderData,function(item,key){
                newOrderData.splice(key,1);
                $scope.filterDatas.splice(key,1);
            });
            LsyStorage.setItem('orderDatas',newOrderData);
        }
    }]);
